import React from 'react'
import { useNavigate } from 'react-router-dom'

const userList = ["zhangsan","lisi","wangwu","zhao"]

export default function Login() {
  const navigate = useNavigate();
  return (
    <div>
      <input type="text" onKeyUp={(e) => {
        if (e.keyCode === 13) {
          if (userList.includes(e.target.value.trim())) {
            localStorage.setItem("userName", e.target.value.trim());
            navigate('/my')
          } else {
            alert("您输入的账号不正确");
            e.target.value = null;
          }
        }
      }}
        placeholder={"请输入用户名按回车登录"}
      />
    </div>
  )
}
